/*
 * TPathOptionsPanel.java
 *
 * Copyright 2008 David D. Emory
 * 
 * This file is part of Five Points. See <http://www.fpdev.org> for
 * additional information regarding the project.
 * 
 * Five Points is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Five Points is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Five Points.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.fpdev.apps.rtemaster.gui;

import org.fpdev.apps.rtemaster.gui.map.MapPanel;
import org.fpdev.util.gui.GUIFactory;
import org.fpdev.core.transit.TransitPath;

import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;

public class TPathOptionsPanel extends JPanel {

  private JComboBox type_;
  private MapPanel mapPanel_;
  private JCheckBox addStops_;

  /**
   * Method CTPathOptionsPanel
   *
   *
   */
  public TPathOptionsPanel(MapPanel mapPanel) {
    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    setBorder(new CompoundBorder(new TitledBorder("Transit Path Options"), new EmptyBorder(2, 4, 2, 4)));//new EmptyBorder(8,8,8,8));

    mapPanel_ = mapPanel;

    type_ = GUIFactory.newComboBox(80); // new JComboBox();
    type_.addItem("Bus");
    type_.addItem("Heavy Rail");
    type_.addItem("Light Rail");
    type_.addItem("Regional Rail");

    type_.addItemListener(new ItemListener() {

      public void itemStateChanged(ItemEvent e) {
        if (e.getStateChange() == e.SELECTED) {
        //mapPanel_.setTPathType(getSelectedType());

        }
      }
    });

    addStops_ = GUIFactory.newCheckBox("Auto-Add Stops");
    addStops_.setSelected(true);

    JPanel mainRow = new JPanel();
    mainRow.setLayout(new BoxLayout(mainRow, BoxLayout.X_AXIS));

    mainRow.add(GUIFactory.newLabel("Type:"));
    mainRow.add(Box.createHorizontalStrut(5));
    mainRow.add(type_);
    mainRow.add(Box.createHorizontalGlue());
    mainRow.add(addStops_);
    add(mainRow);
  }

  public TransitPath.Type getSelectedType() {

    switch (type_.getSelectedIndex()) {
      case 0: return TransitPath.Type.BUS;
      case 1: return TransitPath.Type.METRO;
      case 2: return TransitPath.Type.LIGHTRAIL;
      case 3: return TransitPath.Type.REGIONALRAIL;
    }

    return null;
  }

  public void setSelectedType(TransitPath.Type type) {
    switch(type) {
      case BUS: type_.setSelectedIndex(0); break;
      case METRO: type_.setSelectedIndex(1); break;
      case LIGHTRAIL: type_.setSelectedIndex(2); break;
      case REGIONALRAIL: type_.setSelectedIndex(3); break;
    }
  }

  public void setTypeEnabled(boolean enabled) {
    type_.setEnabled(enabled);
  }

  public boolean getAddStops() {
    return addStops_.isSelected();
  }
}




















